<extend name="public/form"/>
<block name="css"></block>
<block name="content">
    <div class="layui-card-header ">
        <span class="layui-breadcrumb">{{$crumbs|raw}}</span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right"
           href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="layui-card-body layui-tab"><!--选项卡父容器必须包含layui-tab class-->
        <ul class="layui-tab-title">
            <li class="layui-this">站点基本信息</li>
            <li>授权角色</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form id="form1" class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">站点名称</label>
                        <div class="layui-input-block">
                            <input type="hidden" name="id" value="{{$site.id}}">
                            <input type="text" name="title" lay-verify="required" jq-error="请输入站点名称"
                                   placeholder="请输入站点名称" autocomplete="off" class="layui-input "
                                   value="{{$site.title}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">站长</label>
                        <div class="layui-input-block">
                            <input type="text" name="stationmaster" lay-verify="required" placeholder="请输入站长名称" autocomplete="off" class="layui-input "
                                   value="{{$site.stationmaster}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">站点邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" name="email" lay-verify="required|email" jq-error="请输入站点邮箱"
                                   placeholder="请输入站点邮箱" autocomplete="off" class="layui-input "
                                   value="{{$site.email}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备案号</label>
                        <div class="layui-input-block">
                            <input type="text" name="record_no" jq-error="请输入备案号"
                                   placeholder="请输入备案号" autocomplete="off" class="layui-input "
                                   value="{{$site.record_no}}">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="edit">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</block>
<block name="js">
    <script>
        layui.use(['jquery', 'form', 'layer', 'tree', 'util', 'element',], function () {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;
            form.render();
            //监听修改基本信息提交
            form.on('submit(edit)', function (data) {
                let send_json = data.field;
                let url='/admin/site/edit/id/'+send_json.id;
                delete send_json.id;
                $.ajax({
                    url: url,
                    method: 'post',
                    data: send_json,
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.code == 0) {
                            layer.alert("编辑成功", {
                                icon: 6
                            });
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }
                    },
                    error: function (data) {
                        layer.msg('服务器繁忙', {icon: 5});
                    }
                });
                return false;
            });
        });
    </script>
</block>